﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Castle.ActiveRecord;
using System.ComponentModel.DataAnnotations;

namespace ZDSoft.LMS.Domain
{
    [ActiveRecord]
    public class BillingItem:EntityBase
    {
        [Property(NotNull=true,Length=100)]
        [Required(ErrorMessage = "不能为空！")]
        [StringLength(50,ErrorMessage="不能超过50个汉字!")]
        public string ItemName { get; set; }
        /// <summary>
        /// 所属报销单
        /// </summary>
        [BelongsTo(Type = typeof(Billing), Column = "BillingID", Lazy = FetchWhen.OnInvoke)]
        public Billing Billing { get; set; }

        /// <summary>
        /// 费用类型
        /// </summary>
        [BelongsTo(Type = typeof(BillingItemType), Column = "DictionaryID", Lazy = FetchWhen.OnInvoke)]
        public BillingItemType Type { get; set; }

        /// <summary>
        /// 产生费用的人
        /// </summary>
        [BelongsTo(Type = typeof(User), Column = "CostorID", Lazy = FetchWhen.OnInvoke)]
        public User Costor { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        [Property(Length=500)]
        [StringLength(500,ErrorMessage="不能超过250个汉字")]
        public string Remark { get; set; }

        #region 辅助属性
        private int billingItemID;

        public int BillingItemID
        {
            get 
            {
                if (Type != null)
                {
                    return Type.ID;
                }
                return billingItemID;
            }
            set { billingItemID = value; }
        }
        #endregion
    }
}
